package pipeline.fragment;

import javax.vecmath.Color3f;
import javax.vecmath.Vector2f;

import pipeline.misc.Fragment;
import pipeline.misc.FrameBuffer;

/**
 * This FP does a texture lookup rather to determine the color of a fragment. It
 * also uses the z-buffering technique to draw the correct fragment.
 * 
 * @author ags
 */
public class TexturedFP extends FragmentProcessor
{
        Color3f texturec = new Color3f();
        
        
        public int nAttr()
        {
                return 5;
        }
        
        public void fragment(Fragment frag, FrameBuffer frameb)
        {
                float z = frag.attrs[0];
                
                if(z >= frameb.getZ(frag.x, frag.y)) {
                        return;
                }
                
                texture.sample(new Vector2f(frag.attrs[4], frag.attrs[5]), texturec);
                
                frameb.set(frag.x, frag.y, texturec.x*frag.attrs[1], texturec.y*frag.attrs[2], texturec.z*frag.attrs[3], z);
        }
}
